﻿Imports System.Data
Imports System.Data.OleDb
Imports geraLaudosAutomatico.conexao
Imports System.Text

Public Class configuracoesDAO

    Dim sql As New StringBuilder
    Dim i As Integer

    Public Function getConfiguracoes() As configuracoesVO
        Dim configuracao As New configuracoesVO
        Dim objConn As New conexao
        sql.Clear()
        sql.Append("SELECT *FROM CONFIGURACOES")
        Dim oReader As OleDbDataReader
        Try
            Dim oComando As New OleDbCommand(sql.ToString, objConn.abreConexao(True))
            oReader = oComando.ExecuteReader
            While oReader.Read
                configuracao = New configuracoesVO
                configuracao.IDREGISTROLOCK = IIf(Not IsDBNull(oReader("IDREGISTROLOCK")), oReader("IDREGISTROLOCK"), Nothing)
                configuracao.COUNTLOCK = IIf(Not IsDBNull(oReader("COUNTLOCK")), oReader("COUNTLOCK"), Nothing)
            End While
            Return configuracao
        Catch ex As Exception
            Throw ex
        Finally
            objConn.fechaConexao()
        End Try
    End Function


    Public Function udpateConfiguracoes(ByVal countLock As Integer, _
                                   ByVal IdregistroLock As Integer) As Integer

        Dim numReg As Integer = 0
        Dim SQL As New StringBuilder

        Try

            SQL.Append("UPDATE CONFIGURACOES SET COUNTLOCK=@COUNTLOCK, IDREGISTROLOCK=@IDREGISTROLOCK")
            Dim objConn As New conexao
            Dim oComando As New OleDbCommand(SQL.ToString, objConn.abreConexao(True))
            oComando.Parameters.AddWithValue("@COUNTLOCK", countLock)
            oComando.Parameters.AddWithValue("@IDREGISTROLOCK", IdregistroLock)
            i = oComando.ExecuteNonQuery

        Catch ex As Exception
            Throw ex
        End Try
        Return i
    End Function
End Class
